package cn.lysj.framework.foodv2.service;

import cn.lysj.framework.base.BaseService;
import cn.lysj.framework.common.utils.web.ParamUtil;
import cn.lysj.framework.foodv2.domain.StandardLevOne;
import cn.lysj.framework.foodv2.domain.StandardLevTwo;
import cn.lysj.framework.foodv2.repository.StandardLevOneRepository;
import cn.lysj.framework.foodv2.vo.StandVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @author drj
 * @description 一级规格服务层
 * @create 2018-11-09 11:29:51
 **/
@Slf4j
@Service
@Transactional
public class StandardLevOneService implements BaseService<StandardLevOne> {

    @Resource
    private StandardLevOneRepository standardLevOneRepository;

    @Override
    public StandardLevOneRepository getRepository() {
        return standardLevOneRepository;
    }

    @Resource
    private StandardLevTwoService standardLevTwoService;

    public List<StandardLevOne> findByFoodId(String foodId) {
        if (ParamUtil.isBlank(foodId)) {
            return null;
        }
        return standardLevOneRepository.findByFoodId(foodId);
    }


    public List<StandVo> getStandVo(String foodId) {
        List<StandVo> standardVoList = new LinkedList<>();
        List<StandardLevOne> standardLevOneList = getRepository().findByFoodId(foodId);
        for (int i = 0; i < standardLevOneList.size(); i++) {
            List<StandardLevTwo> standardLevTwoList = standardLevTwoService.getRepository().findByStandardLevOneId(standardLevOneList.get(i).getId());
            StandVo standVo = new StandVo();
            standVo.setStandardLevOneId(standardLevOneList.get(i).getId());
            standVo.setFlag(standardLevOneList.get(i).getFlag());
            standVo.setLable(standardLevOneList.get(i).getName());
            standVo.setStandardLevTwoList(standardLevTwoList);
            standardVoList.add(standVo);
        }
        return standardVoList;
    }


}